package com.company;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author Administrator
 */
public class HJ25数据分类处理 {
    public static void main(String[] args) throws IOException {

        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String str;
        while ((str = bf.readLine()) != null) {
            List<Integer> iList = new ArrayList<>();
            Set<Integer> rSet = new HashSet<>();
            String[] iArray = str.split(" ");
            String rStr = bf.readLine();
            String[] rArray = rStr.split(" ");
            // I 数据
            for (int i = 1; i < iArray.length; i++) {
                iList.add(Integer.parseInt(iArray[i]));
            }
            // R 数据
            for (int i = 1; i < rArray.length; i++) {
                rSet.add(Integer.parseInt(rArray[i]));
            }
            // 对R进行去重
            List<Integer> collect = rSet.stream().sorted().collect(Collectors.toList());
            Map<Integer, Integer> map = new HashMap<>();

            // 判断I中是否包含R数据
            int count = 0;

            for (int i1 = 0; i1 < iList.size(); i1++) {
                for (int i = 0; i < collect.size(); i++) {
                    if ((iList.get(i).toString()).contains((collect.get(i).toString()))) {
                        map.put(i, iList.get(i));
                        count++;
                    }
                }
            }
            for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
                System.out.println(entry.getKey() + " " + entry.getValue());
            }

        }

    }
}
